//
//  MoveLineViewCtrl.m
//  adbae
//
//  Created by Tssup on 16/1/19.
//  Copyright © 2016年 com.tssup. All rights reserved.
//

#import "MoveLineViewCtrl.h"

@interface MoveLineViewCtrl ()
{
    NSTimer* timer;
    NSMutableArray* muArrLine;
}
@property (weak, nonatomic) IBOutlet UIImageView *imgViewLine2;
@property (weak, nonatomic) IBOutlet UIImageView *imgViewLine;
@property (weak, nonatomic) IBOutlet UIView *viewLineContainer;
@end

@implementation MoveLineViewCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    muArrLine = [NSMutableArray arrayWithCapacity:2];
    [muArrLine addObject:self.imgViewLine];
    [muArrLine addObject:self.imgViewLine2];
    [self.viewLineContainer.layer setCornerRadius:self.viewLineContainer.frame.size.width/2];
    [self.viewLineContainer.layer setMasksToBounds:YES];
}
-(void)handleTimer:(id)sender
{
    for (int i=0; i<muArrLine.count; i++)
    {
        UIImageView* imgView=muArrLine[i];
        CGRect frame = imgView.frame;
        frame.origin.x = frame.origin.x-5;
        frame.origin.y = frame.origin.y+5;
       // float radian = 45 * M_PI / 180;
       // frame.origin.x =frame.origin.x- cosf(radian) * 2;
       // frame.origin.y =frame.origin.y+ sinf(radian) * 2;
        imgView.frame =frame;
        if (imgView.frame.origin.x<=-(self.moveLineContainer.frame.size.width+imgView.frame.size.width) ||  imgView.frame.origin.y>self.moveLineContainer.frame.size.height)
        {
            [muArrLine removeObjectAtIndex:0];
            UIImageView* imgView1 = [muArrLine lastObject];
            CGRect frame1 = imgView1.frame;
            float radian = 45 * M_PI / 180;
            frame1.origin.x =frame1.origin.x + cosf(radian) * imgView1.frame.size.width;
            frame1.origin.y =frame1.origin.y -  sinf(radian) * imgView1.frame.size.width;
            imgView.frame = frame1;
            [muArrLine addObject:imgView];
           // [timer invalidate];
        }
        //NSLog(@"asdf====%f ===%f",frame.origin.x,frame.origin.y);
    }
    
}
- (IBAction)btnStart:(id)sender
{
    timer = [NSTimer scheduledTimerWithTimeInterval: 0.01
                                             target: self
                                           selector: @selector(handleTimer:)
                                           userInfo: nil
                                            repeats: YES];
}
- (IBAction)btnStop:(id)sender {
    [timer invalidate];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
